//
//  NavigationOriginalViewController.m
//  SkyworthPalmExam
//
//  Created by Arvin Wang on 15/1/19.
//  Copyright (c) 2015年 Arvin Wang. All rights reserved.
//

#import "NavigationOriginalViewController.h"
#import "UIViewController+specialNav.h"
#import "SVProgressHUD.h"
@interface NavigationOriginalViewController ()
{
    float movementDistance;
}
@end

@implementation NavigationOriginalViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationController.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName:[UIColor whiteColor],NSFontAttributeName:[UIFont boldSystemFontOfSize:17.0]};
    
    [self.navigationController.navigationBar setTintColor:[UIColor whiteColor]];
    [self.navigationController.navigationBar setTranslucent:NO];
    if (iOS7Later) {
        [self.navigationController.navigationBar setBarTintColor:KwBlueColor];
    }else{
        [self.navigationController.navigationBar setTintColor:KwBlueColor];
    }
    
//    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"back"] forBarMetrics:UIBarMetricsDefault];
//    self.navigationController.navigationBar.shadowImage = [[UIImage alloc] init];
    
    NSArray *vcsArray = [self.navigationController viewControllers];
    if (vcsArray)
    {
        NSInteger vcCount = vcsArray.count;
        if (vcCount && vcCount>=2)
        {
            [self createLeftButtonWithTitle:nil withTitleColor:nil withLeftImage:@"back" selector:@selector(onTapLeftBarButton)];
        }
    }
}

#pragma mark Custom Method
- (void)onTapLeftBarButton {
    [super.navigationController popViewControllerAnimated:YES];
}


/**
 左边文字按钮

 @param title 文字
 @param selector 函数
 */
- (void)createLeftButton:(NSString *)title selector:(SEL)selector
{
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:title style:UIBarButtonItemStylePlain target:self action:selector];
    self.navigationItem.leftBarButtonItem.tintColor = [UIColor whiteColor];
}

/**
 右边文字按钮
 
 @param title 文字
 @param selector 函数
 */
- (void)createRightButton:(NSString *)title selector:(SEL)selector {
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:title style:UIBarButtonItemStylePlain target:self action:selector];
    self.navigationItem.rightBarButtonItem.tintColor = [UIColor whiteColor];
}

/**
 *  左边图片按钮
 */
-(void)createLeftButtonWithImage:(UIImage *)image selector:(SEL)selector;
{
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] style:UIBarButtonItemStylePlain target:self action:selector];
}

/**
 *  右边图片按钮
 */
-(void)createRightButtonWithImage:(UIImage *)image selector:(SEL)selector;
{
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] style:UIBarButtonItemStylePlain target:self action:selector];
}


/**
 导航中间加图片

 @param image img
 */
- (void)createCenterImgViewWithImg:(UIImage *)image
{
    UIImageView *imgView = [UIImageView new];
    imgView.frame = CGRectMake(0, 0, 60, 40);
    imgView.image = image;
    imgView.contentMode = UIViewContentModeScaleAspectFit;
    self.navigationItem.titleView = imgView;
}

- (void)showHUDWithMessage:(NSString *)message
{
    [[TKAlertCenter defaultCenter] postAlertWithMessage:message];
}


- (void)showSuccAlertWithMessage:(NSString *)message
{
    [SVProgressHUD showSuccessWithStatus:message];
}

- (void)showErrorAlertWithMessage:(NSString *)message
{
     [SVProgressHUD showErrorWithStatus:message];
 
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
